# 在common中存放共有的一些方法
import functools
from flask import  session,g
from Info.models import User
import qiniu
# 获取登陆用户信息
def get_user_info(f):
    @functools.wraps(f)
    def wapper(*args, **kwargs):
        user_id = session.get('user_id')
        user=None
        if user_id:
            user = User.query.get(user_id)
        g.user = user
        return f(*args,**kwargs)
    return wapper


# 七牛云的可以
access_key = 'XtjhDnqIPSU6hOcT1S2qEVyOPYvRjhjSHPfl78Nn'
secret_key = 'RevktLFcf_X58d-YJPRUz7rXFHPfcRIOJlNJf6qO'
bucket_name = 'itcast'


def send_pic(data):
    # 设置你的登录信息key
    q = qiniu.Auth(access_key, secret_key)
    # 设置存储的仓库名称
    token = q.upload_token(bucket_name)
    # 七牛的返回值
    # None 为none会返回一个key 用来标识这个图片的唯一性 1.jpg
    # data 就是外部传递过来图片或者是文件信息
    ret, info = qiniu.put_data(token, None, data)
    print(ret, info)
    return ret
